import java.util.Vector;

import sdljava.SDLException;
import sdljava.event.SDLEvent;


public class Planet extends Location{
	
	private Construction construction;
	private Vector<Resources> planetResources;
	
	public Planet(GameWindow gameWindow, String imageFile) throws SDLException{
		super(gameWindow, imageFile);
	}
	public Planet(GameWindow gameWindow) throws SDLException{
		planetResources = new Vector<Resources>();
		construction = new Construction(gameWindow);
	}
	public void populateMSVector(Vector<MaterialSprite> M,
			Vector<Integer> Available, Vector<String> enumerate) {
		Resources siteResource = new Resources();
		for(int i = 0; i < enumerate.size(); i++){
			Game.E[] EArray = Game.E.values();
			for(int j = 0; j < EArray.length; j++){
				if(Game.E.valueOf(enumerate.get(i)) == EArray[j]){
					SiteMaterials mat = new SiteMaterials(M.get(j), Available.get(i));
					siteResource.getAvailableMaterials().add(mat);
				}
			}
		}
		planetResources.add(siteResource);
	}
	public Construction getConstruction(){
		return construction;
	}
	public void populateChildMSVectors(){
		construction.getSites().get(0).setResources(planetResources.get(0));
		construction.getSites().get(1).setResources(planetResources.get(1));
		construction.getSites().get(2).setResources(planetResources.get(2));
	}
	public void handleEvent(SDLEvent event)throws SDLException{
		if(!construction.getDone()){
			construction.handleEvent(event);
		}
		else{
			if(construction.getCurrentSite().changeLocation == 1){
				if(construction.check()){
					changeLocation = 4;
				}
				else{
					changeLocation = 5;
				}
			}
			else if(construction.getCurrentSite().changeLocation == 2){
				changeLocation = 2;
			}
			resetConstructionSites();
		}
	}
	protected void show() throws SDLException{
		construction.getCurrentSite().show();
	}
	private void resetConstructionSites(){
		construction.setCurrentSite(0);
		for(int i = 0; i < construction.getSites().size(); i++){
			construction.getSites().get(i).setChangeLocation(0);
			construction.getSites().get(i).resetUserAnswer();
		}
		for(int i = 0; i < planetResources.size(); i++){
			planetResources.get(i).resetMaterials();
		}
		construction.resetDone();
	}
}
